package com.unimod.fsml.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Utility class that contains common methods.
 *
 * @author Ivan Lagunov
 */
public class CommonUtils {
    private static final Log log = LogFactory.getLog(CommonUtils.class);

	public static String convertStreamToString(InputStream is) {
		StringBuilder sb = new StringBuilder();
	    byte[] b = new byte[4096];
	    try {
			for (int n; (n = is.read(b)) != -1;) {
			    sb.append(new String(b, 0, n));
			}
		} catch (IOException e) {
            log.error("Cannot convert InputStream to String", e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                log.error("Cannot close InputStream", e);
            }
		}
	    return sb.toString();
	}	
}
